
local upgrade_target = {}
local upgrade_need = {}

--检测是否满足合成规则
function hc_card(hero,need,class,target)
    local list = hero:get_data('拥有天赋表') or {}
    local have = {}
    for _,name in ipairs(need) do
        local temp = list[name]
        if temp then
            table.insert(have,temp)
        end
    end
    --满足条件 开始合成
    if #have==#need then
        for a,temp in ipairs(have) do
            hide_card(temp)

            --temp:remove()
        end
        ac.wait(100,function()
            hero:notify('英雄-获得天赋',hero,target)
            hero.owner:send_msg(('[天赋合成]%s'):format(target))
        end)
    end
end

--检测天赋能否准备合成
function cheak_need(hero,target)
    local need = upgrade_need[target] or {}
    for _,data in ipairs(need) do
        hc_card(hero,data[1],data[2],target)
    end
end

--检测天赋能否开始合成
function cheak_target(hero,name)
    local targets = upgrade_target[name] or {}
    for _,target in ipairs(targets) do
        cheak_need(hero,target)
    end
end

--注册一个合成规则
function register_crad_rule(target,need,class)
    if upgrade_need[target]==nil then
        upgrade_need[target] = {}
    end
    table.insert(upgrade_need[target],{need,class})

    for _,name in ipairs(need) do
        if upgrade_target[name]==nil then
            upgrade_target[name] = {}
        end
        
        table.insert(upgrade_target[name],target)
    end
end




ac.game:event '天赋-检测合成'(function(_,hero,temp)
    cheak_target(hero,temp.name)
end)

